<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  header("location:checklogin.php");
}
//Update Cash Memo Query
$lrNo                   = (isset($_REQUEST['lrNo'])) ? $_REQUEST['lrNo'] : 0;
$branchId               = (isset($_REQUEST['branchId'])) ? $_REQUEST['branchId'] : 0;
$loadingInvoiceDetailId = isset($_POST['hiddenId']) ? $_POST['hiddenId'] : 0;
$cashMemoAmount         = isset($_POST['cashMemoAmount']) && $_POST['cashMemoAmount'] != '' ? $_POST['cashMemoAmount'] : 0;
$billType               = '';
if(isset($_REQUEST['updateBtn']) || isset($_REQUEST['insertBtn']))
{
	$consignor              = isset($_POST['consignor']) && $_POST['consignor'] != '' ? $_POST['consignor'] : "";
	$consignee              = isset($_POST['consignee']) && $_POST['consignee'] != '' ? $_POST['consignee'] : "";
	$cashmemono             = isset($_POST['cashmemono']) && $_POST['cashmemono'] != '' ? $_POST['cashmemono'] : 0;
	$lorryfreight           = isset($_POST['lorryfreight']) && $_POST['lorryfreight'] != '' ? $_POST['lorryfreight'] : 0;
	$octroi                 = isset($_POST['octroi']) && $_POST['octroi'] != '' ? $_POST['octroi'] : 0;
	$octroiNo               = isset($_POST['octroiNo']) && $_POST['octroiNo'] != '' ? $_POST['octroiNo'] : 0;
	$gcNoteNo               = isset($_POST['gcNoteNo']) && $_POST['gcNoteNo'] != '' ? $_POST['gcNoteNo'] : "";
	$description            = isset($_POST['description']) && $_POST['description'] != '' ? $_POST['description'] : "";
	$servicecharges         = isset($_POST['servicecharges']) && $_POST['servicecharges'] != '' ? $_POST['servicecharges'] : 0;
	$formcharges            = isset($_POST['formcharges']) && $_POST['formcharges'] != '' ? $_POST['formcharges'] : 0;
	$hamali                 = isset($_POST['hamali']) && $_POST['hamali'] != '' ? $_POST['hamali'] : 0;
	$iccharges              = isset($_POST['iccharges']) && $_POST['iccharges'] != '' ? $_POST['iccharges'] : 0;
	$demmurage              = isset($_POST['demmurage']) && $_POST['demmurage'] != '' ? $_POST['demmurage'] : 0;
	$total                  = isset($_POST['total']) && $_POST['total'] != '' ? $_POST['total'] : 0;
	$st                     = isset($_POST['st']) && $_POST['st'] != '' ? $_POST['st'] : 0;
	$grandtotal             = isset($_POST['grandtotal']) && $_POST['grandtotal'] != '' ? $_POST['grandtotal'] : 0;
	$receivedFromMS         = isset($_POST['receivedFromMS']) && $_POST['receivedFromMS'] != '' ? $_POST['receivedFromMS'] : "";
	$issueDate              = $_REQUEST['expDateYear']."-".$_REQUEST['expDateMonth']."-".$_REQUEST['expDateDay'];
	$loadingInvoiceDetailId = $_POST['hiddenId'] ? $_POST['hiddenId'] : 0;


  $update = "UPDATE loadingInvoiceDetail
                SET consignor = '".$consignor."',
                    consignee = '".$consignee."',
                    cashMemoDate = '".$issueDate."',
                    cashMemoNo = '".$cashmemono."',
                    lorryFreight = ".$lorryfreight.",
                    octroi = ".$octroi.",
                    octroiNo = ".$octroiNo.",
                    gcNoteNo = '".$gcNoteNo."',
                    cashMemoDesc = '".$description."',
                    serviceCharges = ".$servicecharges.",
                    formCharges = ".$formcharges.",
                    hamali = ".$hamali.",
                    icCharges = ".$iccharges.",
                    demmurage = ".$demmurage.",
                    total = '".$total."',
                    st = ".$st.",
                    grandTotal = '".$grandtotal."',
                    receivedFromMS = '".$receivedFromMS."',
                    cashMemoAmount = ".$cashMemoAmount."
              WHERE loadingInvoiceDetailId = ".$loadingInvoiceDetailId;
  $updateRes = mysql_query($update);
  if(!$updateRes)
  {
  	echo "Update Fail";
  }
  else
  {
  	header("location:cashMemoNew.php");
  }
}
else
{
<<<<<<< .mine
	$masterRow    = "";
	$masterToRow  = "";
	$consignor    = "";
	$consignee    = "";
	$lorryFreight = "";
	$octroi       = "";
	$octroiNo     = "";
	$discription  = "";
	$printStatus  = "";
	$branchCompany   = "";
	$lrAmount     = 0;
	$qty          = 0;
	$dataFound    = 0;
	
	// Loading Invoice Detail Select Query
	$selectLoading ="SELECT loadingInvoiceDetailId,loadingInvoiceId,consignor, consignee, octroi, octroiNo, discription, lrAmount,billType
	                   FROM loadinginvoicedetail
	                  WHERE lrNo = '".$lrNo."'
	                    AND loadingInvoiceId IN (SELECT loadingInvoiceId
	                                               FROM loadinginvoice
	                                              WHERE fromId = ".$branchId.")";
	$selectLoadingRes = mysql_query($selectLoading);
	if($loadingRow = mysql_fetch_array($selectLoadingRes))
	{
		$dataFound = 1;
		$loadingInvoiceDetailId = $loadingRow['loadingInvoiceDetailId'];
		$billType               = $loadingRow['billType'];
	  //From Branch Display Select Query
	  $selectFrom = "SELECT branchName AS fromId
	                   FROM loadinginvoice
	              LEFT JOIN branch ON branch.branchId = loadinginvoice.fromId
	                  WHERE loadingInvoiceId = ".$loadingRow['loadingInvoiceId'];
	  $selectFromRes = mysql_query($selectFrom);
	  $masterRow = mysql_fetch_array($selectFromRes);
	  
	  //To Display Select Query
	  $selectFrom = "SELECT branchName AS toId
	                   FROM loadinginvoice
	              LEFT JOIN branch ON branch.branchId = loadinginvoice.toId
	                  WHERE loadingInvoiceId = ".$loadingRow['loadingInvoiceId'];
	  $selectFromRes = mysql_query($selectFrom);
	  $masterToRow = mysql_fetch_array($selectFromRes);
	  
	 
	  $selectunload = "SELECT  lrNo,consignor,consignee,lorryFreight,octroi,octroiNo,discription,lrAmount,qty,branchCompany,cashMemoAmount
	                          FROM loadinginvoicedetail
	                         LEFT JOIN  loadinginvoice ON loadinginvoice.loadingInvoiceId = loadinginvoicedetail.loadingInvoiceId
	                         LEFT JOIN branch AS toTable ON toTable.branchId = loadinginvoice.toId
	                        WHERE lrNo = ".$_REQUEST['lrNo']."
	                 ORDER BY consignor";
	  $selectunloadRes = mysql_query($selectunload);
	  while($unloadRow = mysql_fetch_array($selectunloadRes))
	  {
	  	$lrNo            = $unloadRow['lrNo'];
	  	$consignor       = $unloadRow['consignor'];
	  	$consignee       = $unloadRow['consignee'];
	  	$lorryFreight    = $unloadRow['lorryFreight'];
	  	$octroi          = $unloadRow['octroi'];
	  	$octroiNo        = $unloadRow['octroiNo'];
	  	$discription     = $unloadRow['discription'];
	  	$lrAmount        = $unloadRow['lrAmount'];
	  	$qty             = $unloadRow['qty'];
	  	$branchCompany   = $unloadRow['branchCompany'];
	  	$cashMemoAmount  = $unloadRow['cashMemoAmount'];
	  }
	}
	else
	{
		header("Location:cashMemoNew.php?dataFound=1");
	}
=======
	$dataFound = 1;
	$loadingInvoiceDetailId = $loadingRow['loadingInvoiceDetailId'];
	$billType               = $loadingRow['billType'];
  //From Branch Display Select Query
  $selectFrom = "SELECT branchName AS fromId
                   FROM loadinginvoice
              LEFT JOIN branch ON branch.branchId = loadinginvoice.fromId
                  WHERE loadingInvoiceId = ".$loadingRow['loadingInvoiceId'];
  $selectFromRes = mysql_query($selectFrom);
  $masterRow = mysql_fetch_array($selectFromRes);
  
  //To Display Select Query
  $selectFrom = "SELECT branchName AS toId
                   FROM loadinginvoice
              LEFT JOIN branch ON branch.branchId = loadinginvoice.toId
                  WHERE loadingInvoiceId = ".$loadingRow['loadingInvoiceId'];
  $selectFromRes = mysql_query($selectFrom);
  $masterToRow = mysql_fetch_array($selectFromRes);
  
 
  $selectunload = "SELECT  lrNo,consignor,consignee,lorryFreight,octroi,octroiNo,discription,lrAmount,qty,branchCompany,cashMemoAmount
                          FROM loadinginvoicedetail
                         LEFT JOIN  loadinginvoice ON loadinginvoice.loadingInvoiceId = loadinginvoicedetail.loadingInvoiceId
                         LEFT JOIN branch AS toTable ON toTable.branchId = loadinginvoice.toId
                        WHERE lrNo = ".$_REQUEST['lrNo']."
                 ORDER BY consignor";
  $selectunloadRes = mysql_query($selectunload);
  while($unloadRow = mysql_fetch_array($selectunloadRes))
  {
  	$lrNo            = $unloadRow['lrNo'];
  	$consignor       = $unloadRow['consignor'];
  	$consignee       = $unloadRow['consignee'];
  	$lorryFreight    = $unloadRow['lorryFreight'];
  	$octroi          = $unloadRow['octroi'];
  	$octroiNo        = $unloadRow['octroiNo'];
  	$discription     = $unloadRow['discription'];
  	$lrAmount        = $unloadRow['lrAmount'];
  	$qty             = $unloadRow['qty'];
  	$branchCompany   = $unloadRow['branchCompany'];
  	$cashMemoAmount  = $unloadRow['cashMemoAmount'];
  }
>>>>>>> .r11
}

include("./bottom.php");
$smarty->assign("lrNo",$lrNo);
$smarty->assign("dataFound",$dataFound);
$smarty->assign("masterRow",$masterRow);
$smarty->assign("masterToRow",$masterToRow);
$smarty->assign("consignor",$consignor);
$smarty->assign("consignee",$consignee);
$smarty->assign("lorryFreight",$lorryFreight);
$smarty->assign("octroi",$octroi);
$smarty->assign("octroiNo",$octroiNo);
$smarty->assign("discription",$discription);
$smarty->assign("lrAmount",$lrAmount);
$smarty->assign("branchCompany",$branchCompany);
$smarty->assign("cashMemoAmount",$cashMemoAmount);
$smarty->assign("qty",$qty);
<<<<<<< .mine
$smarty->assign("loadingInvoiceDetailId",$loadingInvoiceDetailId);

if($billType == 'wob')
=======
$smarty->assign("loadingInvoiceDetailId",$loadingInvoiceDetailId);

if($dataFound == 0)
>>>>>>> .r11
{
	header("Location:cashMemoNew.php?dataFound=1");
}

if($billType == 'wob')
{
  $smarty->display("cashMemo.tpl");
}
else
{
	$smarty->display("cashmemoNotPrint.tpl");
}
?>